package com.hs.biye.controller.admin;

import com.hs.biye.constant.MessageConstant;
import com.hs.biye.excepction.BaseException;
import com.hs.biye.model.DTO.BedRequest;
import com.hs.biye.model.VO.BedVo;
import com.hs.biye.model.entity.Bed;
import com.hs.biye.model.reslut.Result;
import com.hs.biye.model.reslut.ResultPage;
import com.hs.biye.service.BedService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/bed")
public class BedController {

    @Resource
    private BedService bedService;

    //查询病床信息
    @PostMapping("/pages")
    public ResultPage<BedVo> getBedPage(@RequestBody BedRequest bedRequest){
        if (bedRequest == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        return bedService.getPageBed(bedRequest);
    }

    //查询单个根据id
    @GetMapping("/one/{id}")
    public Result<BedVo> getBedOne(@PathVariable Integer id){
        if (id == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        BedVo bedVo = bedService.getOneById(id);
        return Result.success(bedVo);
    }

    //添加
    @PostMapping("/add")
    public Result<Boolean> addBed(@RequestBody BedRequest bedRequest){
        if (bedRequest == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        boolean res = bedService.addBed(bedRequest);
        return Result.success(res);
    }

    //修改
    @PostMapping("/update")
    public Result<Boolean> update(@RequestBody BedRequest bedRequest){
        if (bedRequest == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        boolean res = bedService.updateBed(bedRequest);
        return Result.success(res);
    }

    //删除
    @GetMapping("/delete/{id}")
    public Result<Boolean> deleteById(@PathVariable Integer id){
        if (id == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        boolean res = bedService.removeBed(id);
        return Result.success(res);
    }


    @GetMapping("/getBedNum/{id}")
    public Result<List<Map<String, Integer>>> getBedNum(@PathVariable Integer id){
        if (id == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        List<Map<String, Integer>> bedNum = bedService.getBedNum(id);
        return Result.success(bedNum);
    }

    @GetMapping("/getBedNumId/{id}")
    public Result<List<BedVo>> getBedNumAndId(@PathVariable Integer id){
        if (id == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        List<BedVo> bedNumAdnBedId = bedService.getBedNumAdnBedId(id);
        return Result.success(bedNumAdnBedId);
    }

}
